<?php

namespace Cck\ArticlesSystem;

use Illuminate\Support\Facades\Blade;
use Cck\ArticlesSystem\Http\Models\Tag;
use Illuminate\Support\ServiceProvider;
use Cck\ArticlesSystem\Http\Models\Role;
use Cck\ArticlesSystem\Http\Models\User;
use Cck\ArticlesSystem\Http\Models\Article;
use Cck\ArticlesSystem\Http\Models\HtmlTag;
use Cck\ArticlesSystem\Http\Models\Keyword;
use Cck\ArticlesSystem\Http\Models\Setting;
use Cck\ArticlesSystem\Http\Models\Category;
use Cck\ArticlesSystem\Console\InstallCommand;
use Cck\ArticlesSystem\Http\Models\Permission;
use Cck\ArticlesSystem\Services\HtmlTagService;
use Cck\ArticlesSystem\Http\Models\SettingGroup;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Route;

class ArticlesSystemServiceProvider extends ServiceProvider
{

    public function boot()
    {
        Blade::directive('tag', function (string $tag) {
            /** @var HtmlTagService $htmlTagService */
            $htmlTagService = $this->app->get(HtmlTagService::class);

            return $htmlTagService->getHtml($tag);
        });
    }

    public function register()
    {

        Relation::morphMap([
            'articles' => Article::class,
            'categories' => Category::class,
            'html_tags' => HtmlTag::class,
            'keywords' => Keyword::class,
            'permissions' => Permission::class,
            'roles' => Role::class,
            'settings' => Setting::class,
            'setting_groups' => SettingGroup::class,
            'tags' => Tag::class,
            'users' => User::class,
        ]);

        if ($this->app->runningInConsole()) {
            $this->commands([
                InstallCommand::class
            ]);
        }
    }
}
